import React, { lazy, Suspense } from 'react';
// lazy 是一个引入组件的方法, 以懒加载的形式引入
// Suspense 是一个组件, 可以指定加载组件时的动画
import { Route, Redirect, Switch } from 'react-router-dom';
import Loading from '@/components/Loading';

// react 里的路由懒加载写法
// 引入登录组件
const Login = lazy(() => import('@/views/login/index'))
// 引入首页组件
const Dashboard = lazy(() => import('@/views/dashboard/Dashboard'))
const Index = () => {
  return (
    <Suspense fallback={<Loading></Loading>}>
      <Switch>
        <Route path='/login' component={Login}></Route>
        <Route path='/dashboard' component={Dashboard}></Route>
        <Redirect from='/' to='/login' exact></Redirect>
      </Switch>
    </Suspense>
  );
}

export default Index;
